package com.moetube.search.handler;

import com.moetube.entity.Result;
import com.moetube.entity.StatusCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

//定义同一异常处理类
@ControllerAdvice //这是个增强类
public class BaseExceptionHandler {

    @ExceptionHandler(value = Exception.class) //范围所有Exception类及子类
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        if(e instanceof MyException){
            return new Result(false, StatusCode.ERROR,e.getMessage());
        }
        return new Result(false, StatusCode.ERROR,"当前系统繁忙，请稍后再试！");
    }
}
